/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.hive.ql.optimizer.calcite.rules;

import org.apache.calcite.adapter.druid.DruidQuery;
import org.apache.calcite.rel.core.Filter;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.rules.ProjectFilterTransposeRule;
import org.apache.calcite.rel.rules.PushProjector;
import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories;

/**
 * Rule to push a {@link org.apache.calcite.rel.core.Project}
 * past a {@link org.apache.calcite.rel.core.Filter}
 * when {@code Filter} is on top of a {@link DruidQuery}.
 * TODO: Replace this class with calcite DruidRules.DruidFilterProjectTransposeRule
 * once we upgrade to calcite 1.13
 */
public class HiveDruidProjectFilterTransposeRule
    extends ProjectFilterTransposeRule {

  public static final HiveDruidProjectFilterTransposeRule INSTANCE =
      new HiveDruidProjectFilterTransposeRule();

  private HiveDruidProjectFilterTransposeRule() {
    super(
        operand(Project.class,
            operand(Filter.class, operand(DruidQuery.class, none()))),
        PushProjector.ExprCondition.FALSE,
        HiveRelFactories.HIVE_BUILDER);
  }
}